package com.nikhu.fx.integration.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.nikhu.fx.bom.ExchangeRate;
import com.nikhu.fx.integration.ExchangeRateService;

public class HibernateExchangeRateServiceImpl implements ExchangeRateService {

	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public ExchangeRate get(String id) {
		Session session = sessionFactory.openSession();
		ExchangeRate exchangeRate = (ExchangeRate) session.get(
				ExchangeRate.class, id);
		session.close();
		return exchangeRate;
	}

	public List<ExchangeRate> findAll() {
		Session session = sessionFactory.openSession();
		Query query = session.createQuery("from ExchangeRate");
		List<ExchangeRate> exchangeRates = (List<ExchangeRate>) query.list();
		session.close();
		return exchangeRates;
	}

}
